/*
Copyright © 2024 kaylee
*/
package cmd

import (
	"bbs125Check/consts"
	"io"
	"log/slog"
	"os"

	"github.com/spf13/cobra"
)

// catlogCmd represents the catlog command
var catlogCmd = &cobra.Command{
	Use:   "catlog",
	Short: "查看彩色日志",
	Long:  `查看彩色日志`,
	Run: func(cmd *cobra.Command, args []string) {
		filename, _ := cmd.Flags().GetString("file")
		file, err := os.Open(filename)
		if err != nil {
			slog.Error("无法打开文件", slog.String("文件路径", filename))
			return
		}
		defer file.Close()
		_, err = io.Copy(os.Stdout, file)
		if err != nil {
			slog.Error("无法读取文件内容", slog.String("文件路径", filename))
			return
		}
	},
}

func init() {
	rootCmd.AddCommand(catlogCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// catlogCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	catlogCmd.Flags().StringP("file", "f", consts.ColorLogFilename, "日志文件路径")
}
